//
//  ViewController.swift
//  ijkPlayerManager
//
//  Created by fanxiaoxin_1987@126.com on 11/29/2021.
//  Copyright (c) 2021 fanxiaoxin_1987@126.com. All rights reserved.
//

import UIKit
import SnapKit

class ViewController: UIViewController, VWPlayerControlDelegate {
    
    let m3u81 = "https://video3.douquwuxian.com/ruyizhuan/1/index.m3u8"
    let m3u82 = "https://video3.douquwuxian.com/ruyizhuan/2/index.m3u8"
    
    let player = VWPlayerController()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        self.addChild(self.player)
        self.player.delegate = self
        self.view.addSubview(self.player.view)
        self.layoutPlayer(self.player.view, isFullScreen: self.player.isFullScreen)
        
        self.player.context.title = "我是第一集"
        self.player.context.currentUrl = self.m3u81
        self.player.context.hasNext = true
        self.player.play(for: .init(string: self.m3u81)!)
    }
    
    func layoutPlayer(_ playerView: UIView, isFullScreen: Bool) {
        if isFullScreen {
            playerView.snp.remakeConstraints { make in
                make.top.equalToSuperview()
                make.left.right.equalToSuperview()
                make.height.equalTo(UIScreen.main.bounds.size.height)
            }
        }else{
            playerView.snp.remakeConstraints { make in
                make.top.equalTo(UIApplication.shared.statusBarFrame.height)
                make.left.right.equalToSuperview()
                make.width.equalTo(playerView.snp.height).multipliedBy(375.0 / 212.0)
            }
        }
    }
    func onPlayerNext() {
        self.player.context.title = "我是第二集"
        self.player.context.currentUrl = self.m3u82
        self.player.context.hasNext = false
        self.player.play(for: .init(string: self.m3u82)!, from: 30)
    }
    func onPlayerQuit() {
        
    }
}

